#include "singleton.h"
#include <iostream>
#include <thread>             // std::thread
#include <mutex>              // std::mutex, std::unique_lock
#include <condition_variable> // std::condition_variable

std::mutex mtx;
std::condition_variable cv;
bool ready = false;

void func() {
	std::unique_lock<std::mutex> lck(mtx);
	while (!ready) cv.wait(lck);
	Singleton::GetInstance().Sleep();
}

void go() {
	std::unique_lock<std::mutex> lck(mtx);
	ready = true;
	cv.notify_all();
}

int main()
{
	std::thread threads[10];

	// spawn 10 threads:
	for (int i=0; i<10; ++i)
		threads[i] = std::thread(func);

	std::cout << "10 threads ready to race...\n";
	go();                       // go!

	for (auto& th : threads) th.join();

	std::cerr << '\n';
	return 0;
}
